import java.util.Arrays;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        MyStack stack=new MyStack();
        stack.push(0);
        stack.push(1);
        stack.push(2);
        System.out.println();
        stack.pop();
        System.out.println();
        System.out.println(stack.peek());
        stack.pop();
        stack.pop();
        System.out.println(stack.empty());
    }
}
class MyStack{
    int[] stack;
    int Size;
    MyStack(){
        stack=new int[3];
    }
    private boolean Full(){
        return stack.length==Size;
    }
    private void Grow(){
        this.stack= Arrays.copyOf(stack,2*stack.length);
    }
    public void push(int val){
        if(Full()) {
            Grow();
        }else {
            stack[Size]=val;
            Size++;
        }
    }
    public int pop(){
        if(empty()){
            return -1;
        }else{
            int x=stack[Size-1];
            Size--;
            return stack[x];
        }
    }
    public int peek(){
        if(empty()){
            return -1;
        }else{
            return stack[Size-1];
        }
    }
    public boolean empty(){
        return Size==0;
    }

}
class A{
    int x=0;

    public int  size(Node root){
        if(root.left==null&&root.right==null)
            x++;
        size(root.right);
        size(root.left);

    }
    public int  size(Node root){
        if(root.left==null&&root.right==null)
            return 1;
        return size(root.left)+size(root.right)

    }

}